/**
* AutoSWF - Cody Cushing. March 26, 2009
* Copyright (c) 2009 Cody Cushing
* No use restrictions. Maintain this notice in all versions. 
**/

package com.autoswf.tracker
{
	import flash.events.StatusEvent;
	import flash.net.LocalConnection;
	
	/**
	 * Adaptor for sending tracks via LocalConnection before sending through optional client, used 
	 * by track console, should not be included in production builds. 
	 */
	public class LCTrackClient implements ITrackClient
	{
		protected var trackClient:ITrackClient;
		protected var lc:LocalConnection;
		
		public static const CONNECTION_ID:String = "_autoswf.trackingOutput";
		protected var _connectionId:String = CONNECTION_ID;
		public function get connectionId():String
		{
			return _connectionId;
		}
		public function set connectionId(value:String):void
		{
			_connectionId = value;
		}
		
		
		/**
		 * Constructor.
		 */		
		public function LCTrackClient(trackClient:ITrackClient = null)
		{
			this.trackClient = trackClient;
			lc = new LocalConnection();
			lc.addEventListener(StatusEvent.STATUS, lc_statusEventHandler);
		}


		/**
		 * Send the tracking request over local connection, then pass to actual TrackClient.
		 */
		public function send(value:String):void
		{
			lc.send(_connectionId, "lc_output", value);
			
			if(trackClient)
			{
				trackClient.send(value);
			}
		}
		
		
		protected function lc_statusEventHandler(event:StatusEvent):void
		{
//			trace("Sending on LC: \""+_connectionId+"\" failed, receiving connection probably wasn't opened yet.");
		}
		
	}
}